package com.yilin.commons.util;

import cn.hutool.core.util.CreditCodeUtil;
import cn.hutool.core.util.IdcardUtil;
import cn.hutool.core.util.ReUtil;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegularUtil {
    //验证手机号
    public static boolean  isPhone(String  phone) {
        return ReUtil.isMatch("^(?:(?:\\+|00)86)?1(?:(?:3[\\d])|(?:4[5-79])|(?:5[0-35-9])|(?:6[5-7])|(?:7[0-8])|(?:8[\\d])|(?:9[1589]))\\d{8}$", phone);
    }
    //验证邮箱
    public static boolean  isEmail(String  email) {
        return ReUtil.isMatch("[a-zA-Z0-9_]+@[a-zA-Z0-9_]+(\\.[a-zA-Z0-9]+)+", email);
    }
    //验证身份证
    public static boolean isIdCard(String  idCard) {
        return IdcardUtil.isValidCard(idCard);
    }
    //验证营业执照
    public static boolean isBusinessLicense(String  businessLicense) {
        return CreditCodeUtil.isCreditCode(businessLicense);
    }
    //验证银行卡号
    public static boolean isBankcard(String  bankcard) {
        return ReUtil.isMatch("^[1-9]\\d{9,29}$", bankcard);
    }
    //验证是否包含中文
    public static boolean isChinese(String  chinese) {
        if(chinese==null)return false;
        Pattern p = Pattern.compile("[\u4E00-\u9FA5|\\！|\\，|\\。|\\（|\\）|\\《|\\》|\\“|\\”|\\？|\\：|\\；|\\【|\\】]");
        Matcher m = p.matcher(chinese);
        if (m.find()) {
            return true;
        }
        return false;
    }
    //验证是否全部是数字
    public static boolean isNumber(String  number) {
        return ReUtil.isMatch("[0-9]+",number);
    }
    //验证是否全部是英文字母
    public static boolean isEnglish(String  english) {
        return ReUtil.isMatch("[a-zA-Z]+", english);
    }
    //验证是否全部是英文字母
    public static boolean isLength(String  str,int length) {
        return ReUtil.isMatch("^\\d+|\\S{0,"+length+"}$",str);
    }


    public static void main(String[] args) {
        System.out.println(isBusinessLicense("911201013613067345"));
    }
}
